import wifiManager from '@ohos.wifiManager';
import socket from '@ohos.net.socket';

export class TcpServerHelper {

  tcpServer: socket.TCPSocket = socket.constructTCPSocketInstance()
  getLocalIp(): string {
    const localAddress = resolveIP(wifiManager.getIpInfo().ipAddress);
    return localAddress;
  }
}

function resolveIP(ip: number): string {
  if (ip < 0 || ip > 0xFFFFFFFF) {
    throw ('The number is not normal!');
  }
  return (ip >>> 24) + '.' + (ip >> 16 & 0xFF) + '.' + (ip >> 8 & 0xFF) + '.' + (ip & 0xFF);
}